package com.tuanzi.loan.business.service.templateConf.impl;

import com.tuanzi.loan.business.entity.templateConf.LoanApiModelItembasisEntity;
import com.tuanzi.loan.business.entity.templateConf.LoanApiModelProjectEntity;
import com.tuanzi.loan.business.entity.templateConf.LoanApiModelTypeEntity;
import com.tuanzi.loan.business.repository.templateConf.LoanApiModelProjectRepository;
import com.tuanzi.loan.business.repository.templateConf.LoanApiModelTypeRepository;
import com.tuanzi.loan.business.repository.templateConf.TemplateItemRepository;
import com.tuanzi.loan.business.service.templateConf.TemplateItemService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.core.service.CommonServiceImpl;
import com.tuanzi.loan.core.vo.PageSearcher;
import com.tuanzi.loan.vo.request.templateConf.TemplateItemRequest;
import com.tuanzi.loan.vo.response.templateConf.TemplateItemResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.retry.RetryException;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Slf4j
@Debug
@Service
@Transactional
@Retryable(value = { RetryException.class })
public class TemplateItemServiceImpl extends CommonServiceImpl<LoanApiModelItembasisEntity, Long> implements TemplateItemService {

	@Autowired
	private TemplateItemRepository templateItemRepository;
	@Autowired
	private LoanApiModelProjectRepository loanApiModelProjectRepository;
	@Autowired
	private LoanApiModelTypeRepository loanApiModelTypeRepository;

	@Override
	protected JpaRepository<LoanApiModelItembasisEntity, Long> getRepository() {
		return templateItemRepository;
	}

	@Override
	public Page<TemplateItemResponse> list(PageSearcher<TemplateItemRequest> pageSearcher) {
		return templateItemRepository.list(pageSearcher.getSearchCondition(), pageSearcher.getPageable());
	}

	@Override
	public List<LoanApiModelProjectEntity> getModelProjectList() {
		return loanApiModelProjectRepository.findAll();
	}

	@Override
	public List<LoanApiModelTypeEntity> getModelTypeList() {
		return loanApiModelTypeRepository.findAll();
	}


}
